IdeaBlade DevForce 2010 Help Reference
InvokeServerMethodAsync(String,String,Action<InvokeServerMethodOperation>,Object,Object[]) Method
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityManager Class > InvokeServerMethodAsync Method : InvokeServerMethodAsync(String,String,Action<InvokeServerMethodOperation>,Object,Object[]) Method



fullTypeName
Assembly-qualified type name such as 'MyNamespace.Services, MyAssembly'
methodName
Name of method to be invoked
userCallback
Callback called when the operation completes
userState
Token identifying the asynchronous request
userArguments
Arguments to be passed to method
Asynchronously invokes the specified static (Shared in Visual Basic) method for execution on the server.

Syntax

Visual Basic (Declaration) 
Public Overloads Function InvokeServerMethodAsync( _
   ByVal fullTypeName As String, _
   ByVal methodName As String, _
   ByVal userCallback As Action(Of InvokeServerMethodOperation), _
   ByVal userState As Object, _
   ByVal ParamArray userArguments() As Object _
) As InvokeServerMethodOperation
Visual Basic (Usage)Copy Code
Dim instance As EntityManager
Dim fullTypeName As String
Dim methodName As String
Dim userCallback As Action(Of InvokeServerMethodOperation)
Dim userState As Object
Dim userArguments() As Object
Dim value As InvokeServerMethodOperation
 
value = instance.InvokeServerMethodAsync(fullTypeName, methodName, userCallback, userState, userArguments)

Parameters

fullTypeName
Assembly-qualified type name such as 'MyNamespace.Services, MyAssembly'
methodName
Name of method to be invoked
userCallback
Callback called when the operation completes
userState
Token identifying the asynchronous request
userArguments
Arguments to be passed to method

Exceptions

ExceptionDescription
System.ArgumentExceptionType name must be fully qualified
System.ArgumentExceptionUserState token must be unique for the client
System.Security.SecurityException 

Example

C#Copy Code
// Sample showing asynchronous invocation of server method

// In client class:
private void MakeAsyncCall() {
  EntityManager mgr = new DomainModelEntityManager();
  // Make async call
  Guid myToken = Guid.NewGuid();
  mgr.InvokeServerMethodAsync(new ServerMethodDelegate(Order.GetNumberOfOrdersSlow), 
      InvokeServerMethodAsyncCompleted, myToken, 
 	    new DateTime(1995, 1, 1), new DateTime(1999, 1, 1));
}
private void InvokeServerMethodAsyncCompleted(InvokeServerMethodOperation e) {
  Guid token = (Guid)e.UserState;
  if (!e.Cancelled) {
     MessageBox.Show("my async result = " + Convert.ToInt32(e.Result).ToString());
  }
}

// Sample method defined in Order entity class:
public class Order {
//...

  // ServerMethodDelegate method, called from client
  [AllowRpc]
  public static Object GetNumberOfOrdersSlow(IPrincipal pPrincipal, EntityManager pMgr, params Object[] pArgs) {
     // Sleep to make this slower to show async
     System.Threading.Thread.Sleep(2000);
     DateTime dt1 = pArgs[0] as DateTime;
     DateTime dt2 = pArgs[1] as DateTime;
     return pMgr.Order.Where(o => o.OrderDate >= dt1 && o.OrderDate <= dt2).Count();
  }
}

Remarks

The method called must be marked with the AllowRpcAttribute and correspond to the ServerMethodDelegate signature.

InvokeServerMethodAsync enables a client-side caller to invoke an arbitrary static method on the server using an asynchronous call. The data returned from the server method will be available in the InvokeServerMethodEventArgs passed to the callback provided. The server method is called once only. An outstanding request can be canceled using the CancelAsync method.

Note that this request is run on a separate client thread. That thread will block until the server request completes or is canceled.

This feature is only available in certain editions of DevForce.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.